﻿using System.Collections.Generic;
using System.Linq;

using Insesoft.Entities;
using NHibernate;
using NHibernate.Linq;

namespace InseSoft.UIControllers
{
    public class SolicitudCotizacionController : Controller
    {
        #region Constructors

        public SolicitudCotizacionController() { }

        public SolicitudCotizacionController(ISession session) : base(session) { }

        #endregion

        #region Methods: Public

        public IList<SolicitudCotizacion> Search(SearchCriteria criteria)
        {
            var query = Session.Query<SolicitudCotizacion>()
                .Where(c => c.Empresa == ApplicationSession.Instance.Empresa);
            if (criteria.Cliente != null) query = query.Where(c => c.Cliente == criteria.Cliente);
            if (criteria.Vendedor != null) query = query.Where(c => c.Vendedor == criteria.Vendedor);
            if (criteria.Material != null) query = query.Where(c => c.Material == criteria.Material);
            if (criteria.Linea != null) query = query.Where(c => c.Linea == criteria.Linea);
            if (criteria.Despiece != null) query = query.Where(c => c.Despiece == criteria.Despiece);
            if (criteria.FechaInicial != null) query = query.Where(c => c.Fecha >= criteria.FechaInicial && c.Fecha <= criteria.FechaFinal);

            return query.ToList();
        }

        #endregion
    }
}
